<?php

/**
 * desktop actions.
 *
 * @package    Imaginarium
 * @subpackage desktop
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class desktopActions extends sfActions
{
  
  public function executeTest(sfWebRequest $request) {
    $dt = Doctrine::getTable('Desktop');
    $it = Doctrine::getTable('Imaginarium');
    $ct = Doctrine::getTable('Character');    
      
    $q = $dt->createQuery();
    $this->desktops = $q->execute();   
    $app_status = Doctrine::getTable('ApplicationStatus')->find(ApplicationStatus::CURRENT_DESKTOP_CONFIG);
    if ($app_status->getCurrent() == null && count($this->desktops) > 0) {
        $this->currentDesktop = $this->desktops[0];
        $app_status->setCurrent($this->currentDesktop->getId());
        $app_status->save();
    } else {
        $this->currentDesktop = $dt->find($app_status->getCurrent());
    }

    $this->imaginariums = $this->currentDesktop->getImaginariums();
    
    $q = $ct->createQuery()->orderBy('nickname');    
    $this->characters = $q->execute();
    
    $this->randomIdeas = $this->currentDesktop->getRandomIdeas();
    
  }
  
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
    $dt = Doctrine::getTable('Desktop');
    $it = Doctrine::getTable('Imaginarium');
    $ct = Doctrine::getTable('Character');    
      
    $q = $dt->createQuery();
    $this->desktops = $q->execute();   
    $app_status = Doctrine::getTable('ApplicationStatus')->find(ApplicationStatus::CURRENT_DESKTOP_CONFIG);
    if ($app_status->getCurrent() == null && count($this->desktops) > 0) {
        $this->currentDesktop = $this->desktops[0];
        $app_status->setCurrent($this->currentDesktop->getId());
        $app_status->save();
    } else {
        $this->currentDesktop = $dt->find($app_status->getCurrent());
    }

    $this->imaginariums = $this->currentDesktop->getImaginariums();
    
    $q = $ct->createQuery()->orderBy('nickname');    
    $this->characters = $q->execute();
    
    $this->randomIdeas = $this->currentDesktop->getRandomIdeas();
    
    //$this->forward('default', 'module');
  }
}
